using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Microblaze.Simulator.Engine;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    /// <summary>
    /// Logical and
    /// </summary>
    public class And : Instruction
    {
        public override int CycleCount
        {
            get { return 1; }
        }

        public And()
            : base("and")
        {
        }

        /// <summary>
        /// The contents of register rA are ANDed with the contents of 
        /// register rB; the result is placed into register rD.
        /// </summary>    
        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            uint sa = MicroblazeComponent.ReadRegister(SourceRegisterA);
            uint sb = MicroblazeComponent.ReadRegister(SourceRegisterB);

            // compute and save
            MicroblazeComponent.WriteRegister(DestinationRegister, sa & sb, Address);
        }


        public override string ToString()
        {
            return String.Format("and r{0}, r{1}, r{2}",
                DestinationRegister,
                SourceRegisterA,
                SourceRegisterB
            );
        }
    }
}
